import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// element-plus按需导入
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// 代理地址配置
let baseUrl = 'http://127.0.0.1:9527' //开发环境
baseUrl = 'http://106.52.141.30:9527' //生产环境

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
      imports: ['vue', 'vue-router'], // 自动导入vue、vue-router相关函数，如：ref, reactive, toRef , useRouter 等
    }),
    Components({
      resolvers: [
        // 1. 配置elementPlus采用sass样式配色系统
        ElementPlusResolver({ importStyle: 'sass' }),
      ],
    }),
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'), // 配置路径别名
    },
    extensions: ['.js', '.vue'], // 引入省略扩展名
  },
  css: {
    preprocessorOptions: {
      scss: {
        // 2. 自动导入定制化样式文件进行样式覆盖
        additionalData: `
          @use "@/styles/element/index.scss" as *;
          @use "@/styles/var.scss" as *;
        `,
      },
    },
  },
  server: {
    // open: true,
    port: '5173',
    host: '0.0.0.0',
    proxy: {
      '/api': {
        target: baseUrl, //代理目标端口
        changeOrigin: true, //如果接口跨域，需要进行这个参数配置
        ws: false,
      },
    },
  },
})
